/************************* 类描述 *********************************
 * 礼物管理员 控制器
 *****************************************************************
 */
package com.realgodo.site.web.admin.present;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.application.present.Present;
import com.realgodo.site.service.application.PresentManager;
import com.realgodo.site.web.admin.AdminDefaultController;

@Scope("prototype")
@Results( { @Result(name = "toindex", type = "redirect", location = "${base}/admin/present/") })
public class IndexController extends AdminDefaultController {

	private static final long serialVersionUID = -4376507358082497289L;

	private Page<Present> presentPage = new Page<Present>(PAGE_SIZE);

	@Resource
	private PresentManager presentManager;

	private Present present;

	public String execute() {
		presentPage.setPageNo(presentManager.isParamNotNull(getParamMap(),
				Page.PAGE) ? Integer.valueOf((String) presentManager
				.getParamValue(getParamMap(), Page.PAGE)) : 1);// 查询页数
		presentPage = this.presentManager.findPresents(presentPage);
		super.setPageInfo(presentPage);
		return SUCCESS;
	}

	public String add() {
		if (null != getId()) {
			present = this.presentManager.get(getId());
		}
		return "add";
	}

	public String save() {
		if (null != getPresent()) {
			this.presentManager.save(getPresent());
		}
		return "toindex";
	}

	/****************** getter and setter ***********************/
	public Present getPresent() {
		return present;
	}

	public void setPresent(Present present) {
		this.present = present;
	}

	public Page<Present> getPresentPage() {
		return presentPage;
	}

}
